package org.linlinjava.litemall.core.util;

import org.linlinjava.litemall.db.domain.LumiereCouponStrategy;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;

public class AdminCouponDateUtil {


    public static LocalDateTime[] calculateExpirationTime(LumiereCouponStrategy couponStrategie){
        LocalDateTime startTime=LocalDateTime.now();
        LocalDateTime endTime=LocalDateTime.now();
        //计算时间
        if(couponStrategie.getTimeType()==0){
            //按天
            startTime=LocalDateTime.now();
            //endTime.plusDays(couponStrategie.getDays()).withHour(23).withMinute(59).withSecond(59);
            LocalDate today = LocalDate.now();// 获取当前日期
            LocalDateTime maxDateTime = today.atTime(LocalTime.MAX).withNano(0); // 设置时间为当天最大时间
            endTime=maxDateTime.plusDays(couponStrategie.getDays()-1);
        }else {
            //按范围
            startTime=couponStrategie.getStartTime();
            endTime=couponStrategie.getEndTime();
        }
        LocalDateTime[] localDateTimes = new LocalDateTime[]{startTime,endTime};
        return localDateTimes;
    }

}
